from flask import Flask
import os
import sys
import argparse

# 添加当前目录到Python路径
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
    sys.path.insert(0, current_dir)

# 显式导入所有需要的模块，确保PyInstaller能够正确识别
import models
import blueprints
import blueprints.web
import blueprints.api

def create_app():
    app = Flask(__name__)
    app.secret_key = 'your-secret_key_here_2025'

    # 初始化数据库
    models.init_db()

    # 注册蓝图
    app.register_blueprint(blueprints.web.web_bp)
    app.register_blueprint(blueprints.api.api_bp, url_prefix='/api')

    return app

app = create_app()

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Flask System Demo')
    parser.add_argument('-p', '--port', type=int, default=5000, help='Port to run the server on (default: 5000)')
    parser.add_argument('--host', type=str, default='0.0.0.0', help='Host to run the server on (default: 0.0.0.0)')
    parser.add_argument('--debug', action='store_true', help='Run in debug mode')
    
    args = parser.parse_args()
    
    app.run(host=args.host, port=args.port, debug=args.debug)